KISSY.use("node",function(S,Node){
var $ = Node.all; 
$(".js-search").on("click",function(){
	var nick = $(".js-sinput").val();
	location.href=("/?m=shop&c=gift&a=sendgifts&nick="+nick);
});
$(".js-sinput").on("click",function(){
	if(this.value="请填入旺旺号搜索"){
		this.value="";
	}
});
$(".js-reset").on("click",function(){
	var eid=$(this).attr("data-eid");
	showDialog("重大操作","请注意，您即将清除所有抽奖用户，清除以后，所有用户将被视为首次参与用户。但是系统已记录的用户的购买次数、累计消费、好中差评数据并不会被清空，请确认需要清空所有抽奖用户！<button class=\"button button-primary js-reset-ok\">确认清空</button>","form-horizontal");
	$(".js-reset-ok").on("click",function(){
		closeDialog();
		KISSY.io({
			url: "/?a=user_tmsreset&m=shopmanage&c=wins&eid="+eid,
			success: function(data, textStatus) {
			closeDialog();
				if(parseInt(data.status)>0){
				showDialog("成功！","已成功清除"+parseInt(data.status)+"个用户！","form-horizontal");
				$(".cancel").on("click",function(){
					location.href=("?a=users&c=wins&m=shopmanage");
				});
				}else{
				showDialog("失败","清除失败，可能已经没有用户了","form-horizontal");
				}
			},
			complete: function(data){
			},
			error: function(){
				alert('error');
			}
		});
		
	});	
});
$(".js-deltms").on("click",function(){
	var uid = $(this).attr("data-uid");
	KISSY.io({
			url: "/?a=user_tmsdel&m=shopmanage&c=wins",
			data: {"uid":uid},
			success: function(data, textStatus) {
				if(parseInt(data.status)==1){
				$(".tms"+uid).empty();
				$(".tms"+uid).text(0);
				}else{
				showDialog("失败","更新失败，请重试","form-horizontal");
				}
			},
			complete: function(data){
			},
			error: function(){
				alert('error');
			}
		});
});
$(".js-addtms").on("click",function(){
	var uid = $(this).attr("data-uid");
	showDialog("增加次数","增加次数：<input type=\"text\" class=\"tms\" value=\"1\" />次<button class=\"button button-small js-addtms-add\" >确定</button>","form-horizontal");
	$(".js-addtms-add").on("click",function(){
		var tms = $(".tms").val();
		KISSY.io({
			url: "/?a=user_tmsadd&m=shopmanage&c=wins",
			data: {"uid":uid,"tms":tms},
			success: function(data, textStatus) {
			closeDialog();
				if(parseInt(data.status)==1){
				var t = $(".tms"+uid).text();
				$(".tms"+uid).empty();
				$(".tms"+uid).text(parseInt(t)+parseInt(tms));
				}else{
				showDialog("失败","更新失败，请重试","form-horizontal");
				}
			},
			complete: function(data){
			},
			error: function(){
				alert('error');
			}
		});
	});
});
$(".bui-tab-item").on("click",function(){
		$(".bui-tab-item").removeClass("bui-tab-item-selected");
		$(this).addClass("bui-tab-item-selected");
		var tp = $(this).attr("data-tp");
		var admin = $(this).attr("data-admin");
		var type = $(".type").val();
		if(admin=="user"){
			location.href=("/?m=user&a=gifts&ctp="+tp+(type?"&type="+type:""));
		}else if(admin=="sendgifts"){
			location.href=("/?m=shop&c=gift&a=sendgifts&ctp="+tp+(type?"&type="+type:""));
		}else{
			location.href=("/?m=shop&c=gift&ctp="+tp+(type?"&type="+type:""));
		}
	});
$(".trash").on("click",function(){
	var ctp =$(this).attr("data-ctp");
	location.href=("/?m=shop&c=gift&ctp="+(ctp?ctp:"eggs")+"&type=9");
});
$(".list").on("click",function(){
	var ctp =$(this).attr("data-ctp");
	location.href=("/?m=shop&c=gift&ctp="+(ctp?ctp:"eggs"));
});
$(".cuijiang").on("click",function(){
	var gid=$(this).attr("data-gid");
	KISSY.io({
		url: "/?a=cuijiang&m=user",
		data: {"gid":gid},
		success: function(data, textStatus) {
			if(parseInt(data.status)==1){
			$(".status"+gid).empty();
			$("<span class=\"label label-warning\">催发奖</span>").appendTo(".status"+gid);
			}else{
			showDialog("崔奖失败","您已经崔过了","form-horizontal");
			}
		},
		complete: function(data){
		},
		error: function(){
			alert('error');
		}
	});
});
$(".js-gifttui").on("click",function(){
	var gid = $(this).attr("data-gid");
	var isshow = $(this).attr("data-isshow");
	KISSY.io({
		url: "/?a=tuijian&m=shop",
		data: {"gid":gid,"isshow":isshow},
		success: function(data, textStatus) {
			if(parseInt(data.status)==1){
				if(isshow==0){
					showDialog("推荐成功","推荐成功，该奖品将出现在您所有活动的详情页。","form-horizontal");
					$(".js-g"+gid).removeClass("button-success");
					$(".js-g"+gid).text("取消推荐");
					$(".js-g"+gid).attr("data-isshow","1");
				}else{
					showDialog("取消成功","已取消推荐","form-horizontal");
					$(".js-g"+gid).addClass("button-success");
					$(".js-g"+gid).text("推荐");
					$(".js-g"+gid).attr("data-isshow","0");
				}
			}else{
				showDialog("崔奖失败","推荐失败。。。","form-horizontal");
			}
		},
		error: function(){
			alert('error');
		}
	});
});
$(".fajiang").on("click",function(){
if($(this).attr("data-gtp")!="item"){
showDialog("给用户发奖","除实物奖以外均由用户自行点击奖品发放链接领取奖品！","form-horizontal");
return;
}
var usernick = $(this).attr("data-unick");
if(usernick){
	var dialog=("            <div class=\"row form-horizontal\">");
		dialog+=("                <div class=\"control-group\" style=\"width: 260px;margin: auto;\">");
		dialog+=("                    <label class=\"control-label\">");
		dialog+=("                        填写交易订单号：");
		dialog+=("                    </label>");
		dialog+=("                    <div class=\"controls\">");
		dialog+=("                        <input type=\"text\" class=\"input-normal control-text tradeid\" value=\"\" name=\"tradeid\" />");
		dialog+=("                        <button class=\"queren button button-primary\" data-gid=\""+$(this).attr("data-gid")+"\" >确认发奖</button>");
		dialog+=("                    </div>");
		dialog+=("                </div>");
		dialog+=("            </div>");
}else{
	var dialog = "该用户尚未领取中奖凭证，因此无法发放实物奖！";
}
showDialog("给用户发奖",dialog,"form-horizontal");
$(".cancel").remove();
	$(".queren").on("click",function(){
		var gid=$(this).attr("data-gid");
		var tradeid = $(".tradeid").val();
		if(!tradeid){
			alert("请填写用于发奖的交易订单号！");
			return;
		}
		KISSY.io({
			url: "/?a=fajiang&m=shop",
			data: {"gid":gid,"tradeid":tradeid},
			success: function(data, textStatus) {
				closeDialog();
				if(parseInt(data.status)==1){
				$(".status"+gid).empty();
				$("<span class=\"label label-success\">已发奖</span>").appendTo(".status"+gid);
				}else{
					showDialog("发奖失败！","发奖失败！请检查交易号是否为15位的淘宝订单号","form-horizontal");
				}
			},
			complete: function(data){
				$("<a class=\"button button-mini button-success wuliu\" href=\"http://trade.taobao.com/trade/detail/trade_item_detail.htm?bizOrderId="+data.tid+"\" target=\"_blank\"><i class=\"icon icon-white icon-plane\"></i>查物流</a>").insertAfter(".fa"+gid);
				$(".fa"+gid).remove();
			},
			error: function(){
				alert('error');
			}
		});
	});
});
$(".lingjiang").on("click",function(){
	var gid=$(this).attr("data-gid");
	KISSY.io({
		url: "/?a=lingjiang&m=user",
		data: {"gid":gid},
		success: function(data, textStatus) {
			if(parseInt(data.status)==1||parseInt(data.status)==2){
			var html = "<div style='text-align:center'>恭喜您中奖"+data.giftname+"！点击图片领奖：<br /><a href='"+data.withdraw+"' target='_blank' class='ljcon'><img src='"+data.giftpic+"_240x240.jpg' /></a></div>"
			showDialog("请您领奖",html,"form-horizontal");
				$(".ljcon").on("click",function(){
							KISSY.io({
								url: "/?a=ljconfirm&m=user",
								data: {"gid":gid},
								success: function(data, textStatus) {
									closeDialog();
									if(parseInt(data.status)==1){
									$(".status"+gid).empty();
									$("<span class=\"label label-warning\">已领奖</span>").appendTo(".status"+gid);
										showDialog("请领奖！","请在新打开的窗口中领奖！","form-horizontal");
									}else{
										showDialog("已领过！","已领过该奖品！","form-horizontal");
									}
								},
								complete: function(data){
								},
								error: function(){
									alert('error');
								},
								dataType:"jsonp"
							});
				});
			}else{
				if(parseInt(data.status)==0){
					alert("未发奖");
				}else if(parseInt(data.status)==3){
					alert("崔发奖");
				}else{
					alert("奖品状态有误，请联系管理员");
				}
			}
		},
		complete: function(data){
		},
		error: function(){
			alert('error');
		}
	});

});
});